<template>
  <div class="wrapper">
    <div class="title-wrapper">
      <div class="bigTitle">利润分析</div>
    </div>
    <div style="text-align: right">
      <time-picker class="cus-wrapper" ref="timeRef" @change="handleChange" />
    </div>
    <balance-bar :source="source"/>
  </div>
</template>

<script>
import {sumBankTrade} from "@/api/services/dashboard.service";
import balanceBar from './balance-bar'
import timePicker from './time-picker'
import moment from "moment";


export default {
  name: "balance",
  components: {balanceBar,timePicker},
  data() {
    return {
      source: [],
      currentTime: [],
    }
  },
  mounted() {
    this.$nextTick(() => {
      let time = this.$refs.timeRef.initTime()
      this.handleChange(time)
    })
  },
  methods: {
    handleChange(data) {
      if (!data) return
      this.currentTime = `${data.year}-${data.moment}`
      this.getData()
    },
    getData() {
      let currentTime = this.currentTime
      let params = {stime: '', etime: ''}
      let month = moment(this.currentTime, "YYYY-MM").daysInMonth()
      if (currentTime) {
        params.stime = `${currentTime}-01 00:00:00`
        params.etime = `${currentTime}-${month} 23:59:59`
      }
      sumBankTrade(params).then(res => {
        const {data} = res
        if (data) {
          this.source = [
            {value: data.balance, name: '总利润'},
            {value: data.gath, name: '总支出'},
            {value: data.gath, name: '总收入'}
          ]
        }
      })
    }
  }
}
</script>


<style lang="less">
.cus-wrapper {
  .el-select.selectTime {
    width: 70px !important;
  }
}
</style>
<style lang="less" scoped>
.title-wrapper {
  display: flex;
  justify-content: space-between;

  .bigTitle {
    border-bottom: none;
    padding: 8px 0;
    color: #3A71A8;
    font-size: 18px;
    font-weight: bold;
    white-space: nowrap;
  }
}
.wrapper {
  width: 100%;
}
</style>
